package com.ruoyi.outbound.service.impl;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;
import com.ruoyi.common.core.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.outbound.mapper.BmOutboundMapper;
import com.ruoyi.outbound.domain.BmOutbound;
import com.ruoyi.outbound.service.IBmOutboundService;

/**
 * #出库单Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-08-02
 */
@Service
public class BmOutboundServiceImpl implements IBmOutboundService 
{
    @Autowired
    private BmOutboundMapper bmOutboundMapper;

    /**
     * 查询#出库单
     * 
     * @param outboundCode #出库单主键
     * @return #出库单
     */
    @Override
    public BmOutbound selectBmOutboundByOutboundCode(String outboundCode)
    {
        return bmOutboundMapper.selectBmOutboundByOutboundCode(outboundCode);
    }

    /**
     * 查询#出库单列表
     * 
     * @param bmOutbound #出库单
     * @return #出库单
     */
    @Override
    public List<BmOutbound> selectBmOutboundList(BmOutbound bmOutbound)
    {
        return bmOutboundMapper.selectBmOutboundList(bmOutbound);
    }

    /**
     * 新增#出库单
     * 
     * @param bmOutbound #出库单
     * @return 结果
     */
    @Override
    public int insertBmOutbound(BmOutbound bmOutbound)
    {
        StringBuilder sb = new StringBuilder("CK" + DateUtils.dateTimeNow());
        sb.insert(10, "-");
        bmOutbound.setOutboundCode(sb.toString());
        bmOutbound.setCreateTime(DateUtils.getNowDate());
        return bmOutboundMapper.insertBmOutbound(bmOutbound);
    }

    /**
     * 批量删除#出库单
     * 
     * @param outboundCodes 需要删除的#出库单主键
     * @return 结果
     */
    @Override
    public int deleteBmOutboundByOutboundCodes(String[] outboundCodes)
    {
        return bmOutboundMapper.deleteBmOutboundByOutboundCodes(outboundCodes);
    }

    /**
     * 删除#出库单信息
     * 
     * @param outboundCode #出库单主键
     * @return 结果
     */
    @Override
    public int deleteBmOutboundByOutboundCode(String outboundCode)
    {
        return bmOutboundMapper.deleteBmOutboundByOutboundCode(outboundCode);
    }

    @Override
    public int updateStatus(BmOutbound bmOutbound) {
        bmOutbound.setOutboundTime(DateUtils.getNowDate());
        if (bmOutbound.getStatus() == 1) {
            return bmOutboundMapper.updateStatusTwo(bmOutbound);
        } else {
            return bmOutboundMapper.updateStatus(bmOutbound);
        }
    }
}
